﻿namespace CKFinder.Connector
{
    using CKFinder.Settings;
    using System;
    using System.Collections;

    internal class Config
    {
        private static Config _Current;

        private Config()
        {
        }

        public bool CheckAuthentication()
        {
            return ConfigFile.Current.CheckAuthentication();
        }

        internal bool CheckIsHiddenFile(string fileName)
        {
            return ConfigFile.Current.HideFilesRegex.IsMatch(fileName);
        }

        internal bool CheckIsHiddenFolder(string folderName)
        {
            return ConfigFile.Current.HideFoldersRegex.IsMatch(folderName);
        }

        internal bool CheckIsNonHtmlExtension(string extension)
        {
            string[] htmlExtensions = ConfigFile.Current.HtmlExtensions;
            if (htmlExtensions.Length != 0)
            {
                return !Util.ArrayContains(htmlExtensions, extension, CaseInsensitiveComparer.DefaultInvariant);
            }
            return true;
        }

        public ResourceType GetResourceTypeConfig(string resourceTypeName)
        {
            return ConfigFile.Current.ResourceType.GetByName(resourceTypeName);
        }

        public AccessControlManager AccessControl
        {
            get
            {
                return ConfigFile.Current.AccessControl;
            }
        }

        public bool CheckSizeAfterScaling
        {
            get
            {
                return ConfigFile.Current.CheckSizeAfterScaling;
            }
        }

        public static Config Current
        {
            get
            {
                if (_Current == null)
                {
                    _Current = new Config();
                }
                return _Current;
            }
        }

        public string DefaultResourceTypes
        {
            get
            {
                return ConfigFile.Current.DefaultResourceTypes;
            }
        }

        public bool ForceSingleExtension
        {
            get
            {
                return ConfigFile.Current.ForceSingleExtension;
            }
        }

        public CKFinder.Settings.Images Images
        {
            get
            {
                return ConfigFile.Current.Images;
            }
        }

        public string LicenseKey
        {
            get
            {
                return ConfigFile.Current.LicenseKey.PadRight(0x20, ' ');
            }
        }

        public string LicenseName
        {
            get
            {
                return ConfigFile.Current.LicenseName;
            }
        }

        public ResourceTypeManager ResourceTypes
        {
            get
            {
                return ConfigFile.Current.ResourceType;
            }
        }

        public string RoleSessionVar
        {
            get
            {
                return ConfigFile.Current.RoleSessionVar;
            }
        }

        public bool SecureImageUploads
        {
            get
            {
                return ConfigFile.Current.SecureImageUploads;
            }
        }

        public CKFinder.Settings.Thumbnails Thumbnails
        {
            get
            {
                return ConfigFile.Current.Thumbnails;
            }
        }
    }
}

